package cn.com.dstz.admin.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import cn.com.dstz.web.constants.Constants;
import cn.com.dstz.base.action.BaseAction;

/**
 * 日志表
 * @author 叶装装
 */
public class LoginLogAct extends BaseAction{
	
	
	/**
	 * 获取日志
	 */
	public void list(  ){
		
		Map< String, Object > admin = this.getEntityInSession( Constants.ADMIN_IN_SESSION );
		Integer groupId = ( Integer )admin.get( "groupid" );
		String whereSQL = " 1=1 ";
		Map< String, Object > valueMap = new HashMap< String, Object >( );
		
		if( groupId != 1 ){
			whereSQL = " loginuid=:uid";
			valueMap.put( "uid", admin.get( "id" ) );
		}
		
		String SQL = "select * from dstz_loginlog where " + whereSQL;
		
		this.responseToJsonObject( this.paginationBySQL( SQL, null, valueMap, "logindate" ) );
		return;
	}
	
	/**
	 * 删除日志
	 */
	public void delete( ) {
		String ids = getParameter( "ids" );
		
		if( ids != null ){
			String [] splitIds = StringUtils.split( ids, "," );
			
			if( splitIds != null && splitIds.length > 0 ){
				List< String > delSqls = new ArrayList< String >( );
				
				for( String id : splitIds ){
					if( StringUtils.isNotBlank( id )){
						delSqls.add( "delete from dstz_loginlog where id =" + id);
					}
				}
				
				baseService.saveOrUpdateBatch( delSqls );
			}
		}
		
	}
	
	private static final long serialVersionUID = 1L;
	
}
